// -----------------------------------------------------------------------
//  <copyright file="GetOrganizationByIdQuery.cs" company="LiuliuSoft">
//      Copyright (c) 2022-2024 DaprPlus. All rights reserved.
//  </copyright>
//  <site>https://dapr.plus</site>
//  <last-editor>郭明锋</last-editor>
//  <last-date>2024/12/8 22:01:24</last-date>
// -----------------------------------------------------------------------

using DaprPlus.Identity.Domain.Entities;

using DaprPlus.Identity.Application.Identity.Organizations.Specs;


namespace DaprPlus.Identity.Application.Identity.Organizations.Queries;

[AuthConfig(typeof(Organization), ResourceAccessType.RoleLimit, "GetById")]
public class GetOrganizationByIdQuery(long id) : SingleQuery<OrganizationOutDto?>
{
    public long Id { get; set; } = id;
}

public class OrganizationByIdQueryHandler(IQueryRepository<Organization> queryRepository)
    : IRequestHandler<GetOrganizationByIdQuery, OrganizationOutDto?>
{
    public async Task<OrganizationOutDto?> Handle(GetOrganizationByIdQuery request, CancellationToken cancellationToken)
    {
        var spec = new OrganizationByIdSpec(request.Id);
        var model = await queryRepository.GetAsync(spec, cancellationToken);
        return model?.MapTo<OrganizationOutDto>();
    }
}

